/*
 * Copyright (C) 2016 huanghaibin_dev <huanghaibin_dev@163.com>
 * WebSite https://github.com/MiracleTimes-Dev
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.talkweb.calendarview;

import ohos.agp.colors.RgbColor;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.components.element.ShapeElement;
import ohos.app.Context;

/**
 * 默认星期栏
 *
 * @author Along
 * @time 2021/3/25
 */
public class DefaultWeekBar extends WeekBar {
    public DefaultWeekBar(Context context) {
        super(context);
        LayoutScatter.getInstance(context).parse(ResourceTable.Layout_cv_week_bar, this, true);
    }

    @Override
    void setup(CalendarViewDelegate delegate) {
        super.setup(delegate);
        setTextSize(delegate.getWeekTextSize());
        setTextColor(delegate.getWeekTextColor());
        ShapeElement element = new ShapeElement();
        element.setRgbColor(RgbColor.fromArgbInt(delegate.getWeekBackground()));
        setBackground(element);
        setPadding(delegate.getCalendarPaddingLeft(), 0, delegate.getCalendarPaddingRight(), 0);
    }

    @Override
    protected void onWeekStartChange(int weekStart) {
        ComponentContainer component = (ComponentContainer) getComponentAt(0);
        for (int i = 0; i < component.getChildCount(); i++) {
            ((Text) component.getComponentAt(i)).setText(getWeekString(i, weekStart));
        }
    }

    protected void onDateSelected(Calendar calendar, int weekStart, boolean isClick) {

    }

}
